package com.example.dormmanage.controller;

import com.example.dormmanage.entity.Building;
import com.example.dormmanage.service.impl.BuildingService;
import com.example.dormmanage.view.BuildingDto;
import com.example.dormmanage.view.ResultView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/building")
@Api(tags = "楼宇接口")
public class BuildingController {

    @Autowired
    public BuildingService buildingService;

    @GetMapping()
    @ApiOperation("查询楼宇列表")
    public ResultView<List<BuildingDto>> selectBuildingList(){
        return buildingService.selectBuildingList();
    }

    @GetMapping("/1")
    @ApiOperation("查询楼宇列表")
    @PreAuthorize("hasAuthority('selectBuildingList')")
    public ResultView<List<BuildingDto>> selectBuildingList1(String name){
        return buildingService.selectBuildingList1(name);
    }

    @PostMapping
    @ApiOperation("新增楼宇")
    public ResultView<String> addBuilding(@RequestBody Building building){
        return buildingService.addBuilding(building);
    }
}
